package com.jy.api.domain;

import com.jy.api.util.UuidUtil;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by hanxi on 2017/7/17.
 */
@Entity
@Data
@NoArgsConstructor
public class OrderItem {
    @Id
    @Column(length = 50)
    private String id;
    private String productName;
    private String productId;
    private String productTypeId;

    private double dealPrice = 0;

    private int quantity = 0;
    @Column(insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date addTime;
    @Column(insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;

    private boolean enabled = true;

    private boolean finish = false;

    private int port;

    private String ipAddress;

    /**
     * 是否支持厨房打印
     */
    private boolean kitchenPrintEnabled = false;

    private int setMealId;

    private boolean label = false;

    private boolean already = false;

    private int batch = 1;

    private int spec;

    private String image;

    private String createName;

    private String createMobile;

    public OrderItem(String id, Product product,
                     double salesPrice, double dealPrice, int quantity) {

        this.id = id;
        this.productName = product.getName();
        this.productId = product.getId();
        this.dealPrice = dealPrice;
        this.quantity = quantity;
        this.productTypeId = product.getProductType().getId();
    }

    //测试修改订单详细
    public OrderItem(String id, Product product, int quantity) {
        this.id = id;
        this.productName = product.getName();
        this.productId = product.getId();
        this.quantity = quantity;
        this.productTypeId = product.getProductType().getId();
        this.spec = quantity;
        this.image = product.getImageURL();
    }


    public OrderItem(String id, SetMeal meal, int qty) {
        this.id = id;
        this.productName = meal.getName();
        this.productTypeId = meal.getTypeId();
        this.quantity = qty;
        this.kitchenPrintEnabled = meal.isKitchenPrintEnabled();
        this.setMealId = meal.getId();
    }

    public OrderItem(String id, String productId, String productName,
                     double salesPrice, double dealPrice, int quantity,
                     double commission, String productImageURL) {
        this.id = id;
        this.productName = productName;
        this.productId = productId;
        this.dealPrice = dealPrice;
        this.quantity = quantity;
    }

    public OrderItem(String id, String productId, String productName,
                     double salesPrice, double dealPrice, int quantity, String productTypeId) {
        this.id = id;
        this.productName = productName;
        this.productId = productId;
        this.dealPrice = dealPrice;
        this.quantity = quantity;
        this.productTypeId = productTypeId;
    }


    public OrderItem(OrderItem item) {
        this.id = UuidUtil.getUuid();
        this.productName = item.getProductName();
        if (null != item.getProductId()) {
            this.productId = item.getProductId();
        } else {
            this.setMealId = item.getSetMealId();
        }
        this.productTypeId = item.getProductTypeId();
        this.dealPrice = item.getDealPrice();
        this.quantity = item.getQuantity();
        this.addTime = item.getAddTime();
        this.updateTime = item.getUpdateTime();
        this.enabled = item.isEnabled();
        this.finish = item.isFinish();
        this.kitchenPrintEnabled = item.isKitchenPrintEnabled();
        this.label = item.isLabel();
        this.already = item.isAlready();
        this.batch = item.getBatch();
        this.spec = item.getSpec();
        this.image = item.getImage();
        this.ipAddress=item.getIpAddress();
        this.port=item.getPort();
    }


    public OrderItem(int quantity,Product product,int spec ) {
        this.id = UuidUtil.getUuid();
        this.productName = product.getName();
        this.productId = product.getId();
        this.productTypeId = product.getProductType().getId();
        this.dealPrice = product.getSalesPrice();
        this.quantity = quantity;
        this.finish = true;
        this.port = product.getPort();
        this.ipAddress = product.getIpAddress();
        this.spec = spec;
        this.image = product.getImageURL();
    }


    public OrderItem( int quantity,SetMeal meal ,int spec) {
        this.id = UuidUtil.getUuid();
        this.productName = meal.getName();
        this.productTypeId = meal.getTypeId();
        this.dealPrice = meal.getPrice();
        this.quantity = quantity;
        this.port = meal.getPort();
        this.ipAddress = meal.getIpAddress();
        this.kitchenPrintEnabled = meal.isKitchenPrintEnabled();
        this.setMealId = meal.getId();
        this.spec = spec;
    }

    public void accuracy() {
        dealPrice = Math.rint(dealPrice * 100) / 100d;
    }
}
